package com.ch3;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * @author woldier
 * @version 1.0
 * @description pack打断标记
 * @date 2023/4/18 16:57
 **/
@Slf4j(topic = "c.Thread")
public class ThreadDemo_10 {


    public static void main(String[] args) throws InterruptedException {
        t1();

        //t2();;

    }


    public static void t1() throws InterruptedException {
        Thread thread = new Thread(() -> {

            log.debug("准备pack");
            LockSupport.park();
            log.debug("继续执行1");
            log.debug("查看打断标记, {}", Thread.currentThread().isInterrupted());

            log.debug("尝试再次pack");
            LockSupport.park();
            log.debug("继续执行2");
        }, "pack打断标记");

        thread.start();
        TimeUnit.SECONDS.sleep(2);
        thread.interrupt();
    }

    public static void t2() throws InterruptedException {
        Thread thread = new Thread(() -> {

            log.debug("准备pack");
            LockSupport.park();
            log.debug("继续执行");
            log.debug("查看打断标记并清空, {}", Thread.interrupted());

            log.debug("尝试再次pack");
            LockSupport.park();
            log.debug("继续执行2");
        }, "pack打断标记");

        thread.start();
        TimeUnit.SECONDS.sleep(1);
        thread.interrupt();
    }
}
